home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / help / floating.hl- < prev    next >
Encoding:
Text File  |  1995-02-25  |  13.2 KB  |  403 lines

  1. # floating.hlp  
  2. #
  3. #               floating and floating-ext wordsets
  4. #
  5. # L.C. Benschop 24 sep 1994.
  6. #
  7. # In all stack comments, floats are assumed to be on a separate stack.
  8.  
  9.  
  10. : >FLOAT ( c-addr u --- true|false ) ( F: --- r| ) [FLOATING]
  11. Attempt to convert the character string described by c-addr and u to a
  12. floating point number. If the conversion is successful then a true
  13. flag and r are returned, otherwise only false is returned.
  14.  
  15. If the string consists of all blanks, it is converted to zero.
  16.  
  17. The number may start with an optional plus or minus sign. It must 
  18. contain at least one digit, either before or after the point.
  19. The decimal point is optional. The number may end with an exponent part, 
  20. which starts with one of the letters E, e, D or d. This is followed
  21. by an optional plus or minus sign, followed by zero or more digits.
  22. The exponent letter may be omitted if the exponent sign is present. 
  23. If there are no digits in the exponent part, it is treated as zero.
  24.  
  25.  
  26. : D>F ( d --- ) ( F: --- r )                      [FLOATING]
  27. Convert d to a floating point number. If d cannot be represented exactly,
  28. there is an ambiguous condition.
  29.  
  30.  
  31. : F!  ( f-addr --- ) ( F: r --- )                 [FLOATING]
  32. Store r at address f-addr.
  33.  
  34.  
  35. : F*  ( F: r1 r2 --- r3 )                         [FLOATING]
  36. multiply r1 and r2.
  37. Shouldn't there be an ambiguous condition if overflow?
  38.  
  39.  
  40. : F+  ( F: r1 r2 --- r3 )                         [FLOATING]
  41. Add r1 and r2
  42. Shouldn't there be an ambiguous condition if overflow?
  43.  
  44.  
  45. : F-  ( F: r1 r2 --- r3 )                         [FLOATING]
  46. Subtract r2 from r1.
  47. Shouldn't there be an ambiguous condition if overflow?
  48.  
  49.  
  50. : F/  ( F: r1 r2 --- r3 )                         [FLOATING]
  51. Divide r1 by r2.
  52. If result overflows of r2 is zero, there is an ambiguous condition.
  53.  
  54.  
  55. : F0< ( --- flag ) ( F: r --- )                   [FLOATING]
  56. flag is true if and only if r is less than zero.
  57.  
  58.  
  59. : F0= ( --- flag ) ( F: r --- )                   [FLOATING]
  60. flag is true if and only if r is equal to zero.
  61.  
  62.  
  63. : F<  ( --- flag ) ( F: r1 r2 --- )               [FLOATING]
  64. flag is true if and only if r1 is less than f2.
  65.  
  66.  
  67. : F>D ( --- d ) ( F: r --- )                      [FLOATING]
  68. Convert the integer portion of r to double, discard the fractional part.
  69. If r is outside the range of double numbers, there is an 
  70. ambiguous condition.  
  71.  
  72.  
  73. : F@  ( f-addr --- ) ( F: --- r )                 [FLOATING]
  74. Fetch the value r from address f-addr.
  75.  
  76.  
  77. : FALIGN ( --- )                                  [FLOATING]
  78. Adjust the data space pointer such that it points to a 
  79. float-aligned address.
  80.  
  81.  
  82. : FALIGNED ( addr --- f-addr )                    [FLOATING]
  83. f-addr is the first float-aligned address equal to or higher than
  84. addr.
  85.  
  86.  
  87. : FCONSTANT ( "<spaces>name" --- ) ( F: r --- )   [FLOATING]
  88. Parse name delimited by space and create a definition for name that, 
  89. when executed, pushes  r onto the floating point stack. 
  90.  
  91. name execution: ( F: --- r )
  92.  
  93.  
  94. : FDEPTH  ( --- +n )                              [FLOATING]
  95. +n is the number of numbers on the floating point stack.
  96.  
  97.  
  98. : FDROP   ( F: r --- )                            [FLOATING]
  99. Discard top element from the floating point stack.
  100.  
  101.  
  102. : FDUP    ( F: r --- r r )                        [FLOATING]
  103. Duplicate the top element of the floating point stack.
  104.  
  105.  
  106. : FLITERAL                                        [FLOATING]
  107. Using FLITERAL while interpreting is an error.
  108.  
  109. Compilation: ( F: r --- )  
  110. FLITERAL is an immediate word. Append the following runtime behavior 
  111. to the current definition.
  112.  
  113. Runtime:     ( F: --- r )
  114.  
  115.  
  116. : FLOAT+  ( f-addr1 --- f-addr2 )                [FLOATING] 
  117. Increment f-addr1 by the size of one floating point number.
  118.  
  119.  
  120. : FLOATS  ( n1 --- n2 )                          [FLOATING]
  121. Convert number of floating point numbers to the size in address
  122. units.
  123.  
  124.  
  125. : FLOOR   ( F: r1 --- r2 )                       [FLOATING]
  126. Round r1 to the largest integer not greater than r2.
  127.  
  128.  
  129. : FMAX    ( F: r1 r2 --- r3 )                    [FLOATING]
  130. r3 is the maximum of r1 and r2.
  131.  
  132.  
  133. : FMIN    ( F: r1 r2 --- r3 )                    [FLOATING]
  134. r3 is the minimum of r1 and r2.
  135.  
  136.  
  137. : FNEGATE ( F: r1 --- r2 )                       [FLOATING]
  138. r2 is the negation of r1/
  139.  
  140.  
  141. : FOVER   ( F: r1 r2 --- r1 r2 r1 )              [FLOATING]
  142. Copy the second number of the floating point stack to the top.
  143.  
  144.  
  145. ; FROT    ( F: r1 r2 r3 --- r2 r3 r1 )           [FLOATING]
  146. Rotate the three top numbers on the floating point stack.
  147.  
  148.  
  149. : FROUND  ( F: r1 --- r2 )                       [FLOATING]
  150. Round r1 to the nearest integer. If r1 is exactly halfway 
  151. between to integers, the even integer is chosen.
  152.  
  153.  
  154. : FSWAP   ( F: r1 r2 --- r2 r1 )                 [FLOATING]
  155. Swap the two top numbers on the floating point stack.
  156.  
  157.  
  158. : FVARIABLE ( "<spaces>name" --- )               [FLOATING]
  159. Parse name delimited by spaces and create a definition for name that
  160. pushes f-addr onto the stack. f-addr is the address of a reserved data
  161. space where a floating point number may be stored. 
  162.  
  163. name execution: ( --- f-addr )                 
  164.  
  165.  
  166. : REPRESENT ( c-addr u --- n flag1 flag2 ) ( F: r --- ) [FLOATING]
  167. Convert r to a decimal character representation and place that at 
  168. c-addr. The representation consists of the u most significant digits, 
  169. the first of which is nonzero; only if r=0, the representation consists 
  170. of all zeros. flag2 is true if r is in the range of convertible numbers.
  171. flag1 is true if r is negative. n is the decimal exponent of r. n=0
  172. if abs(r) is greater than or equal to 0.1 and less than 1.0.  
  173.  
  174. r is rounded to the nearest number that can be represented in u 
  175. significant digits prior to conversion; n reflects the situation after 
  176. rounding.
  177.  
  178. If flag2 is false, then n, flag1 and the string at c-addr are 
  179. implementation-defined. The string at c-addr always consists of graphic
  180. ASCII characters.  
  181.  
  182. BASE must contain 10, else there is an ambiguous condition.
  183.  
  184.  
  185. : DF!  ( df-addr --- ) ( F: r --- )              [FLOATING EXT]
  186. Store r at df-addr as an IEEE double precision number. If 
  187. r has more significant bits than the IEEE double precision number, 
  188. it is rounded to the nearest such number. If r is outside the range
  189. of IEEE double precision numbers, there is an ambiguous condition.
  190.  
  191.  
  192. : DF@  ( df-addr --- ) ( F: --- r )              [FLOATING EXT]
  193. Fetch the double precision number stored at df-addr and convert
  194. it to r. If the IEEE double precision number has more significant 
  195. bits than r, it is rounded to the nearest floating point value.
  196. If the IEEE double precision number is outside the range of
  197. floating point numbers, there is an ambiguous condition.
  198.  
  199.  
  200. : DFALIGN ( --- )                                [FLOATING EXT]
  201. Adjust the data space pointer such that it points to a double
  202. float aligned address.
  203.  
  204.  
  205. : DFALIGNED ( addr --- df-addr )                 [FLOATING EXT]
  206. df-addr is the first double float-aligned address greater than
  207. or equal to addr.
  208.  
  209.  
  210. : DFLOAT+   ( df-addr1 --- df-addr2)             [FLOATING EXT]
  211. Increment df-addr1 by the size of one IEEE double precision
  212. floating point number.
  213.  
  214.  
  215. : DFLOATS   ( n1 --- n2 )                        [FLOATING EXT]
  216. Convert number of IEEE double precision floating point numbers 
  217. to the size in address units.
  218.  
  219.  
  220. : F** ( F: r1 r2 --- r3 )                        [FLOATING EXT]
  221. Raise r1 to the power of r2.
  222.  
  223.  
  224. : F.  ( F: r --- )                               [FLOATING EXT]
  225. Display r in a fixed point format with a trailing space.
  226.  
  227. If BASE does not contain 10 or if the character string representation
  228. is larger than the pictured number output buffer, there is an
  229. ambiguous condition.
  230.  
  231.  
  232. : FABS ( F: r1 --- r2 )                          [FLOATING EXT]
  233. Compute the absolute value of r1.
  234.  
  235.  
  236. : FACOS ( F: r1 --- r2 )                         [FLOATING EXT]
  237. Compute the inverse cosine of r1 in radians. abs(r1) must not be 
  238. greater than 1.0, else there is an ambiguous condition.
  239.  
  240.  
  241. : FACOSH ( F: r1 --- r2 )                        [FLOATING EXT]
  242. Compute the inverse hyperbolic cosine of r1. r1 must be at least
  243. one, else an ambiguous condition exists.
  244.  
  245.  
  246. : FALOG ( F: r1 --- r2 )                         [FLOATING EXT]
  247. Raise ten to the power of r1 (inverse logarithm).
  248.  
  249.  
  250. : FASIN ( F: r1 --- r2 )                         [FLOATING EXT]
  251. Compute the inverse sine of r1 in radians. abs(r1) must not be 
  252. greater than 1.0, else there is an ambiguous condition.
  253.  
  254.  
  255. : FASINH ( F: r1 --- r2 )                        [FLOATING EXT]
  256. Compute the inverse hyperbolic sine of r1. If r1 is less than zero,
  257. there is an ambiguous condition. (why?)
  258.  
  259.  
  260. : FATAN  ( F: r1 --- r2 )                        [FLOATING EXT]
  261. Compute the inverse tangent of r1 in radians.
  262.  
  263.  
  264. : FATAN2 ( F: r1 r2 --- r3 )                     [FLOATING EXT]
  265. Compute the angle r3 in radians whose sine and cosine have the
  266. same signs and ratio as r1 and r2. If r1 and r2 are both zero,
  267. there is an ambiguous condition.
  268.  
  269.  
  270. : FATANH ( F: r1 --- r2 )                        [FLOATING EXT]
  271. Compute the inverse hyperbolic tangent of r1. If abs(r1) is
  272. greater than 1.0, there is an ambiguous condition.
  273.  
  274.  
  275. : FCOS ( F: r1 --- r2 )                          [FLOATING EXT]
  276. Compute the cosine of r1 (r1 in radians).
  277.  
  278.  
  279. : FCOSH ( F: r1 --- r2 )                         [FLOATING EXT]
  280. Compute the hyperbolic cosine of r1.
  281.  
  282.  
  283. : FE.   ( F: r --- )                            [FLOATING EXT]
  284. Display r in engineering format, which is similar to scientific
  285. format, but where the significand lies between 1.0 and 1000.0 and
  286. where the decimal exponent is a multiple of 3. 
  287.  
  288. If BASE does not contain 10 or if the character string representation
  289. is larger than the pictured number output buffer, there is an
  290. ambiguous condition.
  291.  
  292.  
  293. : FEXP ( F: r1 --- r2 )                          [FLOATING EXT]
  294. Raise e to the power of r1 (inverse natural logarithm).
  295.  
  296.  
  297. : FEXPM1 ( F: r1 --- r2 )                        [FLOATING EXT]
  298. Raise e to the power of r1 and subtract one. 
  299.  
  300.  
  301. : FLN ( F: r1 --- r2 )                           [FLOATING EXT]
  302. Compute the natural logarithm of r1. r1 must be greater than zero, 
  303. else there is an ambiguous condition.
  304.  
  305.  
  306. : FLNP1 ( F: r1 --- r2 )                         [FLOATING EXT]
  307. Add one to r1 and compute the natural logarithm. r1 must be
  308. greater than -1.0, else there is an ambiguous condition.
  309.  
  310.  
  311. : FLOG ( F: r1 --- r2 )
  312. Compute the base-10 logarithm of r1. r1 must be greater than zero,
  313. else there is an ambiguous condition.
  314.  
  315.  
  316. : FS. ( F: r --- )                               [FLOATING EXT]
  317. Display r in scientific format with a trailing space. The
  318. number starts with an optional minus sign, followed by a digit, a
  319. decimal point, more digits, the letter E, an optional minus sign
  320. and the digits of the decimal exponent. 
  321.  
  322. If BASE does not contain 10 or if the character string representation
  323. is larger than the pictured number output buffer, there is an
  324. ambiguous condition.
  325.  
  326.  
  327. : FSIN ( F: r1 --- r2 )                          [FLOATING EXT]
  328. Compute the sine of r1 (r1 in radians).
  329.  
  330.  
  331. : FSINCOS ( F: r1 --- r2 r3 )                    [FLOATING EXT]
  332. r1 is the angle in radians. r2 is the sine and r3 the cosine.
  333.  
  334.  
  335. : FSINH   ( F: r1 --- r2 )                       [FLOATING EXT]
  336. Compute the hyperbolic sine of r1.
  337.  
  338.  
  339. : FSQRT   ( F: r1 --- r2 )                       [FLOATING EXT]  
  340. Compute the square root of r1. If r1 is less than zero, there is
  341. an ambiguous condition.
  342.  
  343.  
  344. : FTAN    ( F: r1 --- r2 )                       [FLOATING EXT]
  345. Compute the tangent of r1. (r1 in radians) If cos(r1) is zero,
  346. there is an ambiguous condition.
  347.  
  348.  
  349. : FTANH   ( F: r1 --- r2 )                       [FLOATING EXT]
  350. Compute the hyperbolic tangent of r1.
  351.  
  352.  
  353. : F~      ( --- flag ) ( r1 r2 r3 --- )          [FLOATING EXT]
  354. flag is true if and only if r1 and r2 are sufficiently close within
  355. the tolerance r3. If r3>0, then r3 is an absolute tolerance 
  356. (absolute difference between r1 and r2 must not be more than r3). If
  357. r3=0, then r1 and r2 must be exactly equal. If r3<0, it is a relative
  358. tolerance (difference between r1 and r2 must not be more than 
  359. r3*(r1+r2) ).
  360.  
  361.  
  362. : PRECISION ( --- u )                            [FLOATING EXT]
  363. u is the number of significant digits used by F. FE. and FS.
  364.  
  365.  
  366. : SET-PRECISION ( u --- )                        [FLOATING EXT]
  367. Set the number of significant digits used by F, FE. and FS.
  368.  
  369.  
  370. : SF!  ( sf-addr --- ) ( F: r --- )              [FLOATING EXT]
  371. Store r at sf-addr as an IEEE single precision number. If 
  372. r has more significant bits than the IEEE single precision number, 
  373. it is rounded to the nearest such number. If r is outside the range
  374. of IEEE single precision numbers, there is an ambiguous condition.
  375.  
  376.  
  377. : SF@  ( sf-addr --- ) ( F: --- r )              [FLOATING EXT]
  378. Fetch the single precision number stored at sf-addr and convert
  379. it to r. If the IEEE single precision number has more significant 
  380. bits than r, it is rounded to the nearest floating point value.
  381. If the IEEE single precision number is outside the range of
  382. floating point numbers, there is an ambiguous condition.
  383.  
  384.  
  385. : SFALIGN ( --- )                                [FLOATING EXT]
  386. Adjust the data space pointer such that it points to a single
  387. float aligned address.
  388.  
  389.  
  390. : SFALIGNED ( addr --- sf-addr )                 [FLOATING EXT]
  391. sf-addr is the first single float-aligned address greater than
  392. or equal to addr.
  393.  
  394.  
  395. : SFLOAT+   ( sf-addr1 --- sf-addr2)             [FLOATING EXT]
  396. Increment sf-addr1 by the size of one IEEE single precision
  397. floating point number.
  398.  
  399.  
  400. : SFLOATS   ( n1 --- n2 )                        [FLOATING EXT]
  401. Convert number of IEEE single precision floating point numbers 
  402. to the size in address units.
  403.